//
//  HeroTableViewController.m
//  LOL视频播放
//
//  Created by 花花蔡 on 2016/12/14.
//  Copyright © 2016年 com.HuaHuaCai. All rights reserved.
//

#import "HeroTableViewController.h"
#import "HeroTableViewCell.h"
#import "Public.h"
#import <MJRefresh.h>
#import <MJExtension.h>
#import "URL.h"
#import "NetWorkingTool.h"
#import "HeroModel.h"
#import "OneHeroViewController.h"
@interface HeroTableViewController ()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic,strong) NSMutableArray *dataArray;


@end

@implementation HeroTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"英雄";
    [self loadMoreData];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.rowHeight = 110 * KWidth_ScaleW;
    self.tableView.separatorInset = UIEdgeInsetsMake(0, 5, 0, 5);
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
    [self.tableView.mj_header beginRefreshing];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - 加载数据
- (void)loadMoreData {
    self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        
        [[NetWorkingTool sharedTools] requestMethod:GET WithURL:ALLHERO_URL parameters:nil callBack:^(id data, NSError *error) {
            
            if (error) {
                [self.tableView.mj_header endRefreshing];
            }
            _dataArray = [HeroModel mj_objectArrayWithKeyValuesArray:data[@"Data"]];
            [self.tableView reloadData];
            [self.tableView.mj_header endRefreshing];
        }];
    }];
}

#pragma mark - Table view data source

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
//#warning Incomplete implementation, return the number of rows
    return _dataArray.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    HeroTableViewCell *cell = [HeroTableViewCell loadCellWithTableView:tableView];
    cell.model = _dataArray[indexPath.row];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    OneHeroViewController *oneHeroVC = [[OneHeroViewController alloc] init];
    
    HeroModel *model = _dataArray[indexPath.row];
    
    oneHeroVC.heroId = model.Id;
    oneHeroVC.cName = model.CName;
    
    [self.navigationController pushViewController:oneHeroVC animated:YES];
}

@end
